/**
 * @name 袁天乐
 * @time 2021/08/14 08:53
 */
import React, { Suspense } from "react"
import { Route, Redirect, Switch } from "react-router-dom"
function routerAurh(props) {
    //传入路由信息
    const { routerConfig, location } = props
    //拿到 token 
    const token = localStorage.getItem('userInfo');
    // let { pathname } = location
    // if( pathname != "/" && !token) {
    //     return <Redirect exact to="/"  />
    // }else if( pathname === "/" && token ){
    //     alert("请先退出当前账号！！")
    //     return <Redirect exact to="/home"  />
    // }
    return (
        <Suspense fallback={<div>Loading...</div>} >
            <Switch>
                {routerConfig.map((item, index) => {
                    let Com = item.component;
                    if (item.from) {
                        return (
                            <Redirect from={item.from} exact to={item.to} key={index} />
                        )
                    }
                    return (
                        <Route
                            key={index} path={item.pathname} render={(props) => {
                                if (item.children) {
                                    return (<Com {...props} routerConfig={item.children} />)
                                } else {
                                    return (<Com {...props} />)
                                }
                            }}
                        ></Route>
                    )

                })}
            </Switch>



        </Suspense>
    )
}

export default routerAurh
